package com.wish.g3.account.controller;


import com.wish.common.core.utils.poi.ExcelUtil;
import com.wish.common.core.web.controller.BaseController;
import com.wish.common.core.web.domain.AjaxResult;
import com.wish.common.core.web.page.TableDataInfo;
import com.wish.common.log.annotation.Log;
import com.wish.common.log.enums.BusinessType;
import com.wish.common.security.annotation.RequiresPermissions;
import com.wish.g3.account.entity.CwCheckBatch;
import com.wish.g3.account.service.ICwCheckBatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 对账批次表 前端控制器
 * </p>
 *
 * @author wish
 * @since 2022-11-23
 */
@RestController
@RequestMapping("/batch")
public class CwCheckBatchController extends BaseController {

    @Autowired
    private ICwCheckBatchService tbCwCheckBatchService;

    /**
     * 查询对账批次列表
     */
    @RequiresPermissions("account:batch:list")
    @GetMapping("/list")
    public TableDataInfo list(CwCheckBatch tbCwCheckBatch)
    {
        startPage();
        List<CwCheckBatch> list = tbCwCheckBatchService.list();
        return getDataTable(list);
    }

    /**
     * 导出对账批次列表
     */
    @RequiresPermissions("account:batch:export")
    @Log(title = "对账批次", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CwCheckBatch tbCwCheckBatch)
    {
        List<CwCheckBatch> list = tbCwCheckBatchService.list();
        ExcelUtil<CwCheckBatch> util = new ExcelUtil<CwCheckBatch>(CwCheckBatch.class);
        util.exportExcel(response, list, "对账批次数据");
    }

    /**
     * 获取对账批次详细信息
     */
    @RequiresPermissions("account:batch:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbCwCheckBatchService.getById(id));
    }

    /**
     * 新增对账批次
     */
    @RequiresPermissions("account:batch:add")
    @Log(title = "对账批次", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CwCheckBatch tbCwCheckBatch)
    {
        return toAjax(tbCwCheckBatchService.save(tbCwCheckBatch));
    }

    /**
     * 修改对账批次
     */
    @RequiresPermissions("account:batch:edit")
    @Log(title = "对账批次", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CwCheckBatch tbCwCheckBatch)
    {
        return toAjax(tbCwCheckBatchService.saveOrUpdate(tbCwCheckBatch));
    }

    /**
     * 删除对账批次
     */
    @RequiresPermissions("account:batch:remove")
    @Log(title = "对账批次", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbCwCheckBatchService.removeByIds(Arrays.asList(ids)));
    }

}
